package com.qf.common;

import com.qf.constants.CommonConstants;

/**
 * --- 愿此行终抵群星 --- *
 *
 * @ author WangHaoYu
 * @ date 2025-04-07
 * @ desc
 */
public class R {
    /**
     * code,指状态码,
     * 随意定,200 是正确,500 错误
     * 50000 请求超时
     * 60000 没有权限
     * msg,指信息描述
     * data,返回的数据
     */
    private int code;
    private String msg;
    private Object data;


    public static R ok() {
        R r = new R();
        r.setCode(CommonConstants.SUCCESS);
        r.setMsg("成功");
        return r;
    }

    public static R ok(Object data) {
        R r = new R();
        r.setCode(CommonConstants.SUCCESS);
        r.setMsg("成功");
        r.setData(data);
        return r;
    }


    public static R fail() {
        R r = new R();
        r.setCode(CommonConstants.FAIL);
        r.setMsg("失败");
        return r;
    }

    public static R fail(String msg) {
        R r = new R();
        r.setCode(CommonConstants.FAIL);
        r.setMsg(msg);
        return r;
    }

    public static R error(int i, String errorMsg) {
        R r = new R();
        r.setCode(i);
        r.setMsg(errorMsg);
        return r;
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
